package com.china08.yxyapi.api.manage.sch.platform.website.setting;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSetting;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSettingRepository;

@CrossOrigin
@RestController
public class SwsSettingFloatAdDetailController extends YxyApiBaseController {

    @Autowired
    SwsSettingRepository swsSettingRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/website/setting/floatAd/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody(required = false) ReqModel reqModel) {

        String schoolId = getProfile(request, response).getSchoolId();
        Assert.isTrue(StringUtils.isNotBlank(schoolId), "学校ID为空");

        SwsSetting swsSetting = swsSettingRepository.findBySchoolId(schoolId);
        Assert.isTrue(null != swsSetting, "域名对象为空");

        RespModel respModel = new RespModel();
        String id = swsSetting.getSchoolId();
        String floatAdImg = swsSetting.getFloatAdImg();
        String floatAdURL = swsSetting.getFloatAdURL();
        boolean floatAdVisable = swsSetting.getFloatAdVisable();

        respModel.id = id;
        respModel.floatAdImg = floatAdImg;
        respModel.floatAdURL = floatAdURL;
        respModel.floatAdVisable = floatAdVisable;
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public String id;
        public String floatAdURL;
        public String floatAdImg;
        public boolean floatAdVisable;
    }

}
